package com.javaweb.service.impl;

import com.javaweb.common.BusinessConstants;
import com.javaweb.dao.ArticleDao;
import com.javaweb.dao.UserDao;
import com.javaweb.service.ArticleService;
import com.javaweb.service.dto.ArticleConditionDto;
import com.javaweb.service.dto.ArticleDto;
import com.javaweb.service.dto.ArticleUpdateDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/10/16 9:47
 */

@Service
@Slf4j
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private UserDao userDao ;
    @Autowired
    private ArticleDao articleDao ;
    // 根据条件查询文章

    // 根据条件查询文章
    public List<ArticleDto> findArticlesByCondition(ArticleConditionDto articleCond) {
        return articleDao.findByConditions(articleCond);
    }

    // 新增文章
    public ArticleDto addArticle(ArticleDto articleDto) {
        articleDao.save(articleDto);
        return articleDto;
    }

    // 更新文章
    public ArticleUpdateDto updateArticle(ArticleUpdateDto articleUpdateDto) {
        articleDao.update(articleUpdateDto);
        return articleUpdateDto;
    }

    // 发布文章
    public void publishArticle(String articleId) {
        articleDao.publish(articleId);
    }

}
